<template>
  <div>
    <van-nav-bar
      title="乐购"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <van-tabs v-model="active" @click="onClick">
      <van-tab
        :title="item.name"
        :name="item.name"
        v-for="item in nav"
        :key="item.id"
      >
        <div class="title">
          <p class="top">{{ item.name }}</p>
          <p class="bottom">{{ item.front_desc }}</p>
        </div>
       
      </van-tab>
    </van-tabs>
    <!-- <p>{{item.name}}</p> -->
    <van-grid :border="false" :column-num="2" :gutter="6">
      <van-grid-item v-for="item in list" :key="item.id" :to="{path:'/category/detail',query:{id:item.id}}">
        <div></div>
        <van-image :src="item.list_pic_url" />
        <p class="desc">{{ item.name }}</p>
        <p class="price">￥{{ item.retail_price }}</p>
      </van-grid-item>
    </van-grid>
     <div><p class="notice">数据库暂无数据...</p></div>
    <!-- :to="{ path: '/category/detail', query: {id: item.id}}" -->
  </div>
</template>

<script>
// import goodsList from '@/api/category/categorList'
import { categoryNav, goodsList } from "@/api/category/categoryList";
export default {
  data() {
    return {
      nav: {},
      active: "",
      list: {},
    };
  },
  created() {
    this.init();
    console.log(this.$route.query.id);
  },

  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    init() {
      categoryNav({
        id: this.$route.query.id,
      }).then((res) => {
        // console.log(res);
        this.nav = res.navData;
        this.active = res.currentNav.name;
      });
      goodsList({
        categoryId: this.$route.query.id,
      }).then((res) => {
        this.list = res.data;
        // this.nav = res.data
      });
    },
    onClick(val) {
      var id = this.nav.find((el) => el.name == val).id;
      console.log(id);
      goodsList({
        categoryId: id,
      }).then((res) => {
        console.log(res);
        this.list = res.data;
      });
    },
  },
};
</script>
<style lang="scss">
// .nav {
//   background-color: #fff;
// }
.price {
  color: #9c3232;
  font-size: 0.32rem;
}
.title {
  text-align: center;
  background: #fff;
  padding: 0.4rem;
  margin-top: 0.26667rem;
  margin-bottom: 0.06667rem;
  .top {
    margin-bottom: 0.24rem;
    font-size: 0.4rem;
    color: #333;
  }
  .bottom {
    display: block;
    height: 0.32rem;
    font-size: 0.32rem;
    color: #999;
  }
}
.desc {
  margin: 0.2rem 0 0.29333rem 0;
  text-align: center;
  padding: 0 0.26667rem;
  font-size: 0.32rem;
}
.notice{
      text-align: center;
    margin-top: 1.33333rem;
    margin-bottom: 1.33333rem;
    color: #999;
}
</style>